from flask_sqlalchemy import SQLAlchemy

# 创建SQLAlchemy实例
db = SQLAlchemy()

# 月收入剩余
class MonthlyBudget(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    budget = db.Column(db.Float, nullable=False)
    remaining = db.Column(db.Float, nullable=False)
    month = db.Column(db.Integer, nullable=False)  # 添加月份字段
    year = db.Column(db.Integer, nullable=False)  # 添加年份字段


# 支出
class Expense(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    amount = db.Column(db.Float, nullable=False)
    date = db.Column(db.Date, nullable=False)
    month = db.Column(db.Integer, nullable=False)
    year = db.Column(db.Integer, nullable=False)
    description = db.Column(db.String(255))


# 定时事件
class ScheduledEvent(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    interval_days = db.Column(db.Integer, nullable=False)  # 间隔天数
    execution_time = db.Column(db.Time, nullable=False)  # 执行时间（时分）
    event_type = db.Column(db.String(10), nullable=False)  # 类型：收入或支出
    amount = db.Column(db.Float, nullable=False)  # 金额
    last_executed = db.Column(db.Date, nullable=True)  # 上次执行时间
    description = db.Column(db.String(255))  # 描述
    skip_weekends = db.Column(db.Boolean, default=False, nullable=False)  # 是否跳过周末
    enabled = db.Column(db.Boolean, default=True, nullable=False)  # 是否启用
